home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / wb-tools / noclick / noclick.c < prev    next >
C/C++ Source or Header  |  1996-06-09  |  5KB  |  321 lines

  1. /*
  2. **    NoClick
  3. **
  4. **        © 1996 by Timo C. Nentwig
  5. **        All Rights Reserved !
  6. **
  7. **        Tcn@techbase.in-berlin.de
  8. **
  9. */
  10.  
  11. /// #include
  12.  
  13. #include <devices/trackdisk.h>
  14.  
  15. #include <dos/dos.h>
  16.  
  17. #include <exec/types.h>
  18.  
  19. #include <libraries/commodities.h>
  20.  
  21. #include <proto/commodities.h>
  22. #include <proto/exec.h>
  23.  
  24. #include <pragmas/commodities_pragmas.h>
  25. #include <pragmas/exec_pragmas.h>
  26.  
  27. #include <stdio.h>
  28.  
  29. ///
  30. /// #define
  31.  
  32. #define PRG_VERSION    "1.0"
  33. #define PRG_TITLE      "NoClick"
  34. #define PRG_AUTHOR     "Timo C. Nentwig"
  35. #define PRG_YEAR       "1996"
  36.  
  37. ///
  38.  
  39.     // Prototypes
  40.  
  41. STATIC VOID              ProcessMsg      (VOID);
  42. STATIC BOOL              AttachFilter    (STRPTR onkey, ULONG user_event);
  43. STATIC VOID __regargs    DriveClick      (BOOL On);
  44.  
  45.     // Version
  46.  
  47. STATIC BYTE    __ver[]     =   "$VER: " PRG_TITLE " " PRG_VERSION " " __AMIGADATE__;
  48.  
  49.     // Externals
  50.  
  51. struct    Library         *CxBase;
  52. struct    MsgPort         *broker_mp;
  53. CxObj                     *broker;
  54. ULONG                      cxsigflag;
  55. BOOL                       fullheight;
  56.  
  57. /// main ()
  58.  
  59. VOID
  60. main (UWORD argc, STRPTR *argv)
  61. {
  62.  
  63.     if (CxBase = OpenLibrary ("commodities.library", 37))
  64.     {
  65.  
  66.         if (broker_mp = CreateMsgPort())
  67.         {
  68.  
  69.             STRPTR   *ttypes;
  70.             struct    NewBroker    newbroker =
  71.             {
  72.  
  73.                 NB_VERSION,
  74.                 PRG_TITLE,
  75.                 PRG_TITLE " " PRG_VERSION " © " PRG_YEAR " by " PRG_AUTHOR,
  76.                 "Disable drive clicking",
  77.                 NBU_UNIQUE | NBU_NOTIFY,
  78.                 0, 0, 0, 0
  79.  
  80.             };
  81.  
  82.             newbroker.nb_Port = broker_mp;
  83.             cxsigflag         = 1L << broker_mp->mp_SigBit;
  84.  
  85.             ttypes            = ArgArrayInit (argc, argv);
  86.             newbroker.nb_Pri  = (BYTE) ArgInt (ttypes, "CX_PRIORITY", 0);
  87.  
  88.             if (broker = CxBroker (&newbroker, NULL))
  89.             {
  90.  
  91.                 CxMsg   *msg;
  92.  
  93.                     // Disable clicking
  94.  
  95.                 DriveClick (FALSE);
  96.  
  97.                 ActivateCxObj (broker, 1L);
  98.                 ProcessMsg();
  99.  
  100.                 DeleteCxObjAll (broker);
  101.  
  102.                 while (msg = (CxMsg *) GetMsg (broker_mp))         // Empty the port of all CxMsgs
  103.                     ReplyMsg ((struct Message *) msg);
  104.  
  105.             }
  106.  
  107.             DeletePort (broker_mp);
  108.  
  109.         }
  110.  
  111.         ArgArrayDone();
  112.         CloseLibrary (CxBase);
  113.  
  114.     }
  115.     else
  116.     {
  117.  
  118.         printf ("ERROR: Couldn't open commodities.library v37+\n");
  119.  
  120.     }
  121.  
  122. }
  123.  
  124. ///
  125. /// ProcessMsg ()
  126.  
  127.     /*
  128.      *    FROM        /rkm/libs/commodities/hotkey.c
  129.      *
  130.      *    FUNCTION    Process commodity messages.
  131.      *
  132.      *    NOTE
  133.      *
  134.      *    EXAMPLE     ProcessMsg ();
  135.      *
  136.      */
  137.  
  138.  
  139. STATIC VOID
  140. ProcessMsg (VOID)
  141. {
  142.  
  143.     CxMsg   *msg;
  144.     ULONG    sigrcvd;
  145.     ULONG    msgid;
  146.     ULONG    msgtype;
  147.     LONG     returnvalue = 1L;
  148.  
  149.     while (returnvalue)
  150.     {
  151.  
  152.         sigrcvd = Wait (SIGBREAKF_CTRL_C | cxsigflag);
  153.  
  154.         while (msg = (CxMsg *) GetMsg (broker_mp))
  155.         {
  156.  
  157.             msgid   = CxMsgID   (msg);
  158.             msgtype = CxMsgType (msg);
  159.             ReplyMsg ((struct Message *) msg);
  160.  
  161.             switch (msgtype)
  162.             {
  163.  
  164.                 case CXM_COMMAND:
  165.  
  166.                     switch (msgid)
  167.                     {
  168.  
  169.                         case CXCMD_DISABLE:
  170.  
  171.                             ActivateCxObj (broker, 0L);
  172.                             break;
  173.  
  174.                         case CXCMD_ENABLE:
  175.  
  176.                             ActivateCxObj (broker, 1L);
  177.                             break;
  178.  
  179.                         case CXCMD_KILL:
  180.  
  181.                             returnvalue = 0L;
  182.                             break;
  183.  
  184.                         case CXCMD_UNIQUE:
  185.  
  186.                             returnvalue = 0L;
  187.                             break;
  188.  
  189.                     }
  190.                     break;
  191.  
  192.             }
  193.  
  194.         }
  195.  
  196.         if (sigrcvd & SIGBREAKF_CTRL_C)
  197.             returnvalue = 0L;
  198.  
  199.     }
  200.  
  201.         // Enable clicking
  202.  
  203.     DriveClick (TRUE);
  204.  
  205. }
  206.  
  207. ///
  208. /// AttachFilter ()
  209.  
  210.     /*
  211.      *    FROM        /CloseWB/CloseWB.c
  212.      *
  213.      *    FUNCTION    Attach a filter.
  214.      *
  215.      *    NOTE
  216.      *
  217.      *    EXAMPLE     AttachFilter (hotkey, EVT_HOTKEY);
  218.      *
  219.      */
  220.  
  221.  
  222. STATIC BOOL
  223. AttachFilter (STRPTR onkey, ULONG user_event)
  224. {
  225.  
  226.     CxObj   *filter;
  227.     CxObj   *sender;
  228.     CxObj   *translator;
  229.  
  230.  
  231.     if (filter = CxFilter (onkey))
  232.     {
  233.  
  234.         AttachCxObj (broker, filter);
  235.  
  236.        if (sender = CxSender (broker_mp, user_event))
  237.        {
  238.  
  239.            AttachCxObj (filter, sender);
  240.  
  241.            if (translator = CxTranslate (NULL))
  242.            {
  243.  
  244.                AttachCxObj (filter, translator);
  245.  
  246.                if ( ! (CxObjError (filter)))
  247.                    return (TRUE);
  248.  
  249.            }
  250.  
  251.        }
  252.  
  253.     }
  254.  
  255.     return (FALSE);
  256.  
  257. }
  258.  
  259. ///
  260. /// DriveClick ()
  261.  
  262.     /*
  263.      *    FROM        /yak/wbstartup/clickdrive.c
  264.      *
  265.      *    FUNCTION    Enable or disable drive clicking
  266.      *
  267.      *    NOTE        TRUE   =  drive clicking off
  268.      *                FALSE  =  drive clicking on
  269.      *
  270.      *    EXAMPLE     DriveClick (TRUE);
  271.      *
  272.      */
  273.  
  274.  
  275. STATIC VOID __regargs
  276. DriveClick (BOOL On)
  277. {
  278.  
  279.              struct    IOExtTD          *td;
  280.              struct    MsgPort          *po;
  281.              struct    TDU_PublicUnit   *tpu;
  282.     REGISTER ULONG     unit;
  283.  
  284.     if (po = CreatePort (NULL, 0) )
  285.     {
  286.  
  287.         for (unit = 0; unit < 4; unit++)
  288.         {
  289.  
  290.             if (td = (struct IOExtTD *) CreateExtIO (po, sizeof (struct IOExtTD)) )
  291.             {
  292.  
  293.                 if ( ! (OpenDevice ("trackdisk.device", unit, (struct IORequest *) td, 0L)))
  294.                 {
  295.  
  296.                     tpu = (struct TDU_PublicUnit *) td -> iotd_Req.io_Unit;
  297.  
  298.                     if (On)
  299.                         tpu -> tdu_PubFlags &= ~TDPF_NOCLICK;           // Keep on clicking !
  300.                     else
  301.                         tpu -> tdu_PubFlags |= TDPF_NOCLICK;            // Stop clicking !
  302.  
  303.                     CloseDevice ( (struct IORequest *) td);
  304.  
  305.                 }
  306.  
  307.                 DeleteExtIO ( (struct IORequest *) td);
  308.  
  309.             }
  310.  
  311.         }
  312.  
  313.         DeletePort (po);
  314.  
  315.     }
  316.  
  317. }
  318.  
  319. ///
  320.  
  321.